home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / Epic4_mos / share / epic / script / imap < prev    next >
Encoding:
Text File  |  2002-10-28  |  6.7 KB  |  227 lines

  1. # imap version 1.0  by Ian Frechette.
  2. # To give credit where credit is due, this was inspired by Run's
  3. # ircmap2 script.  I looked at it once and decided it was slow and kludgy to
  4. # deal with and wrote my own.  All code here is original to me.
  5. #
  6. # Currently the only commands  are
  7. # /initmap [stuff]        - which will create a the data by issuing a /links 
  8. #                         from the current server.
  9. #                         - stuff can be whatever.. The map is split up if you
  10. #                         you try to use stuff.. try   '*.ca *'
  11. # /gomap [server_name]    - will show the current map of the visible irc
  12. #                         network.  If a servername is given it'll try to
  13. #                         recurse outward from that server instead of the
  14. #                         current server.
  15. # Note: you may issue the /gomap command as many times as you want after
  16. # the data has been created.  You may also /initmap at any time to update the
  17. # data.
  18. #
  19. # Note Also.. as of yet hostmasks are not possible, nor would they really
  20. # make much sense.
  21. #
  22. # This script has been modified to work correctly on the EPIC client.
  23. #
  24.  
  25. ^set novice off
  26. ^set max_recursion 50
  27.  
  28. @ RCS.imap = [$$Header: /home/cvs/repository/epic4/script/imap,v 1.2 2002/01/03 19:39:56 crazyed Exp $$]
  29. eval @ map.mask = encode(*.)
  30. # @ map.str = [| | | | | | | | | | | | | | | | | | | | | | | ]
  31.  
  32. #  It starts builds the map data list.   working on args now
  33. alias initmap {
  34.     echo *** imap: removing any old map data around
  35.     purge maplist
  36.     purge maplist2
  37.     purge maphublist
  38.     echo *** imap: building links list to use later
  39.     echo *** imap: please wait until it's finished .....
  40.     map.buildlist $*
  41. }
  42.  
  43. # This alias may take a server name as an argument or it may 
  44. # be left blank.
  45. # gomap tries to display the entire irc map from the point of view of
  46. # the given server or if no arg is given from the server the list was
  47. # built on.
  48. alias gomap {
  49.     if ([$0] != [])
  50.         {@ map.toptree = encode($tolower($0))}
  51.         {@ map.toptree = encode($tolower($map.from))}
  52.     echo *** Displaying map from $decode($map.toptree)
  53.     echo 0   $decode($map.toptree)
  54.     makemap 1 $map.toptree
  55.     map.restore
  56.     echo *** imap: done displaying map
  57. }
  58.  
  59. # used internally to build the actual map data list.  Takes no args.
  60. # This also constructs a list of hostmasks to be used by map.cleanmasks
  61. alias map.buildlist 
  62. {
  63.     ^on ^364 * {
  64.         @ map.from = [$0]
  65.         @ map.srv = [$1]
  66.         @ map.uplink = [$2]
  67.         @ map.hops = [$3]
  68. #        ^set status_user2 . 
  69.         if (left(1 $map.srv) == [*]) {
  70.             @ mapmasklist[$encode($tolower($map.srv))] = map.srv
  71.         }
  72.         @ map.hub = encode($tolower($map.uplink))
  73.         @ maphublist[$map.hub] = maphublist[$map.hub] + 1
  74.         @ maplist[$map.hub][$encode($tolower($map.srv))] = map.hops
  75. #        ^set status_user2  .
  76.     }
  77.     ^on ^365 * {
  78.         ^on 364 -*
  79.         echo *** imap: Done building links list
  80.         ^set -status_user2
  81.         ^on 365 -*
  82.         @ map.tmp = encode($tolower($map.from))
  83.         ^assign -maplist[$map.tmp][$map.tmp]
  84.         @ maphublist[$map.tmp] = maphublist[$map.tmp] - 1
  85.         map.cleanmasks
  86.         map.save
  87.         echo *** imap: you may now issue a /gomap to view irc map
  88.         ^set show_end_of_msgs $map.old_seom
  89.     }
  90.     @ map.old_seom = SHOW_END_OF_MSGS
  91.     ^set show_end_of_msgs on
  92.     //links $*
  93. }
  94.  
  95. # called after the initial list is constructed.  no args.
  96. # This go through the main list of hubs and strips the names down to 
  97. # the hostmask so..  hub goren.u.washington.edu becomes *.washington.edu
  98. # the mask are determined from the servername field so this step cannot
  99. # be done until after the data list is complete
  100. alias map.cleanmasks {
  101.     foreach mapmasklist ii {
  102.         foreach maplist jj {
  103.             if (match(*$mid(2 100 $ii) $jj))
  104.             {
  105.                 foreach maplist.$jj kk {
  106.                     @ maplist[$ii][$kk] = maplist[$jj][$kk]
  107.                     ^assign -maplist[$jj][$kk]
  108.                 }
  109.                 @ maphublist[$ii] = maphublist[$jj]
  110.                 ^assign -maphublist[$jj]
  111.             }
  112.         }
  113.         ^assign -mapmasklist[$ii]
  114.     }
  115.     echo *** imap: map data masks have been cleaned
  116. }
  117.     
  118.  
  119. # used for debugging only
  120. # /showmap  will show you a list of the raw data.  Lists all hub servers
  121. #           sorted alphabetically with leafs of that hub following
  122. # a servername may be supplied as an argument and this will list only
  123. # the info for that one hub
  124. alias showmap {
  125.     if ([$0] == [])
  126.     {
  127.         foreach maplist ii {
  128.             foreach maplist.$ii jj {
  129.                 echo $decode($ii) links $decode($jj)
  130.             }
  131.         }
  132.     }
  133.     {
  134.         foreach maplist.$encode($tolower($0)) ii {
  135.             foreach maplist.$ii jj {
  136.                 echo $decode($ii) links $decode($jj)
  137.             }
  138.         }
  139.     }
  140. }
  141.  
  142. # called with  makemap level server
  143. # this is the real workhorse.. It's a recursive function.. It starts at
  144. # recursion level 1 and follows the servers through the data.
  145. # The following example doesn't use real argument types.
  146. # e.g.   makemap 1 colorado  looks at colorado's list of links
  147. #                            displays each one and then recurses into that
  148. #                            link if it can.  So when it gets to uiuc 
  149. #                            makemap is  called.   makemap 2 uiuc
  150. #                            and it follows it's links etc etc..
  151. # loops in the data are avoided by removing each link from the list entirely
  152. # as it's used.  map.restore can be called later to restore data
  153. #             
  154. alias makemap {
  155.     @ map.ind[$0] = 0
  156.     foreach maplist.$1 ii$0 {
  157.         echo $lformat(3 $0) $map.outmask(1 $0)`-$decode($(ii$0)) $maplist[$1][$(ii$0)]
  158.         ^assign -maplist[$1][$(ii$0)]
  159.         if ((map.ind[$0] = map.ind[$0] +1) >= maphublist[$1])
  160.         {@mask[$0] = 0}
  161.         {@mask[$0] = 1}
  162.         makemap ${[$0] + 1} $(ii$0)
  163.         ^assign -ii$0
  164.     }
  165. }
  166.  
  167. # called after the data is created and cleaned to keep for future use
  168. # no args
  169. alias map.save {
  170.     foreach maplist ii {
  171.         foreach maplist.$ii jj {
  172.             @ maplist2[$ii][$jj] = maplist[$ii][$jj] 
  173.         }
  174.     }
  175.     echo *** imap: Map data saved
  176. }
  177.  
  178.  
  179. # called after gomap has run makemap to restore data.
  180. # makemap destroys the entire list on purpose
  181. # no args.
  182. alias map.restore {
  183.     foreach maplist2 ii {
  184.         foreach maplist2.$ii jj {
  185.             @ maplist[$ii][$jj] = maplist2[$ii][$jj] 
  186.         }
  187.     }
  188.     echo *** imap: Map data restored
  189. }
  190.  
  191. # no stranger to the default scripts.. repeated here for completeness.
  192. alias lformat {
  193.     @ IRCII.word = [$1-]
  194.     if (@IRCII.word < [$0]) 
  195.         { @ function_return = [$([$0]IRCII.word)] } 
  196.         { @ function_return = IRCII.word } 
  197. }
  198.  
  199. # /purge <structure name>
  200. # removes all assignments under that name recursively.
  201. ^alias purge {
  202.   foreach $0 ii
  203.   {
  204.     purge $0.$ii
  205.   }
  206.   ^assign -ii
  207.   ^assign -$0
  208. }
  209.  
  210. # This special little recursive function scans the mask[]
  211. # array and generates an output string of the format
  212. # | |   |   | |  and so on.. depending on whether a mask[x] is
  213. # turned on or not
  214. alias map.outmask {
  215.     if ([$0] < [$1]) 
  216.     {
  217.         if (mask[$0])
  218.             {@ mask.mask = mask.mask ## [| ]}
  219.             {@ mask.mask = mask.mask ## [  ]}
  220.         @ function_return = map.outmask(${[$0] + 1} $1)
  221.     }
  222.     {
  223.         @ function_return = mask.mask
  224.         ^assign -mask.mask
  225.     }
  226. }
  227.